package com.example.gulimall.search.controller;

import com.example.gulimall.search.service.ElasticSearchService;
import com.example.gulimall.search.vo.SearchParam;
import com.example.gulimall.search.vo.SearchResult;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author GuLin
 * @date 2021-06-21 10:51
 */
@Controller
public class SearchController {

    @Autowired
    ElasticSearchService elasticSearchService;

    /**
     * 搜索页面
     * @author GuLin
     * @date 10:53 2021/6/21
     * @return java.lang.String
     **/
    @GetMapping(value = "/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request){
        //1、根据传递来的页面的查询参数，去es中检索商品
        param.set_queryString(request.getQueryString());//_queryString是个字段-面包屑信息
        SearchResult result = elasticSearchService.search(param);
        model.addAttribute("result",result);
        return "list";
    }
}
